var $table;  
var selectionIds = [];  //保存选中ids  
var sysBaseDataField = dataObject.sysBaseDataField;
var singleStatus;
var toolbar = "toolbar_dialog";
var isSelected = true;
var baseDataType = "";
$(function () {
	  var columns =[
                       {field: 'state', checkbox: true},
                       {field: 'baseName' , title: sysBaseDataField.baseName, sortName:'BASE_NAME' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'baseType' , title: sysBaseDataField.baseType, sortName:'BASE_TYPE' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'status' , title: sysBaseDataField.status, formatter: 'statusFormatter', sortName:'STATUS' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'type' , title: sysBaseDataField.type, sortName:'TYPE' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'key' , title: sysBaseDataField.key, sortName:'KEY' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'value' , title: sysBaseDataField.value, sortName:'VALUE' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'language' , title: sysBaseDataField.language, sortName:'LANGUAGE' , sortable: true,halign: 'center',align: 'center'},
                       {field: 'action', title: pageData.action, formatter: '$table.actionFormatter', events: 'actionEvents', clickToSelect: false, width: 150, halign: 'center', align: 'center'}
                   ];
    $table = new BSTable("table", 'sys/sysbasedata/list', columns,"toolbar",560,'id','ID','sysbasedata');
    var queryParams = function(params) {            
         return {
         	       page: params.pageNumber,
         	       limit: params.pageSize,
         	       sidx: params.sortName,
                   order: params.sortOrder,
                   baseName:vm.search.baseName,
                   type:vm.search.type,
              //查询字段
             };
     }
	$table.setQueryParams(queryParams);
    $table.init();
});


var vm = new Vue({
	el:'#app',
	data:{
		showList: true,
		title: null,
		sysBaseData: {	
				baseType : 2,
				status : 2
		},
		search:{
            baseName:"",
		}
	},
	methods: {
		query: function () {
			defaultActions.query();
		},
		add: function(){
			  
		    vm.sysBaseData={
						baseType : 2,
						status : 2,
						type : baseDataType
		    };
			defaultActions.add(vm);
		},
		update: function (event, id) {
		    defaultActions.update(id, $("#table"),$path+"/sys/sysbasedata/info/", vm, function(r){
	        	vm["sysBaseData"] = r["sysBaseData"];
	        });
		},
		saveOrUpdate: function (event) {
		    $('#defaultForm').bootstrapValidator('validate');
			if($('#defaultForm').data('bootstrapValidator').isValid()){
				 var url = vm.sysBaseData.id == null || vm.sysBaseData.id == ''? $path+"/sys/sysbasedata/save" : $path+"/sys/sysbasedata/update";
				 defaultActions.saveOrUpdate(url ,vm, $("#defaultForm"),"sysBaseData",event);
			}
		},
		del: function (event, id) {
		    defaultActions.del(id, $path+"/sys/sysbasedata/delete", $("#table") ) ;
		},
		audit:function(status){
			defaultActions.audit(status , $path+"/sys/sysbasedata/audit?status="+status, vm);
		},
		reload: function (event) {
		    defaultActions.reload($("#table"),$("#defaultForm"),vm,"sysBaseData"); 
		},
		detail: function (event, id) {
			defaultActions.detail(vm, id, event);
		},
	}
});

/*表单校验 start*/
$('#defaultForm').bootstrapValidator({
    feedbackIcons: vail.feedbackIcons(),
    fields: {
               baseName: vail.REPEAT("字典名称",sysBaseDataField.baseName,"25",$path+"/sys/sysbasedata/checkExist","sysBaseData","id","baseName","BASE_NAME"),
		    
    }
});
/*表单校验 end*/
